package main

import (
	"fmt"
	"github.com/zing-dev/general-protocol-lib/log"
	"math/rand"
	"net"
	"time"
)

var message = func(msgType byte, distance float32) []byte {
	return []byte(fmt.Sprintf("msgType:%d$id:85412$equipNo:192.168.1.23$port:1$areaNo:1-2-3$modeType:2-2-7$distance:%f-%f-%f$createTime:%s$realtimedata:#over#1231241234", msgType, distance, distance+200, distance-199, time.Now().Format("2006-01-02 15:04:05")))
}

func main() {
	log.Init()
	conn, err := net.Dial("tcp", ":8500")
	if err != nil {
		log.L.Fatal(err)
	}
	log.L.Info("success")
	for {
		var _, err = conn.Write(message(byte(rand.Intn(10)), rand.Float32()*5+1000))
		if err != nil {
			log.L.Fatal(err)
		}
		var d = make([]byte, 100)
		n, err := conn.Read(d)
		if err != nil {
			log.L.Error(err)
		}
		fmt.Println("返回结果", string(d[:n]))
		if time.Now().Second()%5 == 0 {
			conn.Write([]byte("msgType:99,info:1"))
		}
		time.Sleep(time.Second)
	}
}
